package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * wangcong
 * 2025/2/16 10:35
 */
@RestController
@RequestMapping("/alert-rule")
public class AlertRuleController extends BaseController {
    @Autowired
    AlertRuleService alertRuleService;

    @PostMapping("/create")
    public ResponseResult create(@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.create(alertRuleDto);
        return success();
    }
    @GetMapping("/get-page")
    public ResponseResult<PageResponse<AlertRuleVo>> getPage(
            Integer pageNum,
            Integer pageSize,
            String alertRuleName,
            String functionName,
            String productKey
    ){
        PageResponse<AlertRuleVo> pageResponse = alertRuleService.getPage(pageNum, pageSize, alertRuleName, functionName, productKey);
        return success(pageResponse);
    }
    @GetMapping("/read/{id}")
    public ResponseResult<AlertRuleVo> read(@PathVariable Long id) {
        AlertRuleVo alertRuleVo = alertRuleService.read(id);
        return success(alertRuleVo);
    }

    @PutMapping("/update/{id}")
    public ResponseResult update(@PathVariable Long id, @RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.update(id, alertRuleDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        alertRuleService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        alertRuleService.updateStatus(id, status);
        return success();
    }

}
